package com.longcheer.weibo.vo;

import java.io.Serializable;
import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;

import com.longcheer.weibo.util.Utils;
import com.weibo.net.WeiboException;

public class Comment extends Message implements Serializable {
    private static final long serialVersionUID = -5740703759037154084L;

    private Date createdAt;                 // 评论时间
    private long id;                        // 评论id
    private String text;                    // 评论内容
    private String source;                  // 内容来源
    private Comment replycomment;           // 回复的评论内容
    private User user;                      // User对象
    private Status status;                  // Status对象
    private Comment comments;               // 评论对象
    
    public Comment(JSONObject json)throws WeiboException {
        super(json);
        try {
            id = json.getLong("id");
            text = json.getString("text");
            source = json.getString("source");
            createdAt = Utils.parseDate(json.getString("created_at"),
                    "EEE MMM dd HH:mm:ss z yyyy");
            if (!json.isNull("comments"))
                comments = new Comment(json.getJSONObject("comments"));
            if (!json.isNull("user"))
                user = new User(json.getJSONObject("user"));
            if (!json.isNull("status"))
                status = new Status(json.getJSONObject("status"));
        } catch (JSONException e) {
            throw new WeiboException(e.getMessage() + ":" + json.toString(), e);
        }
    }
    
    @Override
    public MessageType getType() {
        return MessageType.MSG_COMMENT;
    }

    @Override
    public Date getCreatedAt() {
        return createdAt;
    }

    @Override
    public long getId() {
        return id;
    }

    public String getText() {
        return text;
    }

    public String getSource() {
        return source;
    }

    public Comment getReplycomment() {
        return replycomment;
    }

    public User getUser() {
        return user;
    }

    public Status getStatus() {
        return status;
    }

    public Comment getComments() {
        return comments;
    }
}
